﻿/*
 * FileName: BattingEngineAI.cs
 * Module: Core
 * Author: Gourav Das
 * Created: 10 June 2011
 * Modifications:
 * Copyright: Gourav Das, 2011
 */

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using _22yards.EnumDeclarations;
using _22yards.Core.MatchPlayEngine;
using _22yards.Core;

namespace _22yards.Core.BattingEngineAI
{
    public class BattingEngineAI
    {
        private static BattingEngineAI SingletonInstance;
        private Match match;
        private Random rnd;
        private cPlayer BatsmanFacing;
        private short BatsmanSkillPoints;

        /// <summary>
        /// Prevents a default instance of the <see cref="BattingEngineAI"/> class from being created.
        /// </summary>
        private BattingEngineAI()
        {
            rnd = new Random();
            BatsmanFacing = null;
        } //End of ctor

        /// <summary>
        /// Returns a singleton instance of BattingEngineAI
        /// </summary>
        /// <returns>Singleton BattingEngineAI Instance</returns>
        public static BattingEngineAI Init()
        {
            if (SingletonInstance == null)
                SingletonInstance = new BattingEngineAI();

            return SingletonInstance;
        } //End of Init

        /// <summary>
        /// Initializes the required lists and variables for the current batsman
        /// </summary>
        /// <param name="_BattingTeam">The batting team.</param>
        /// <param name="_match">The Match.</param>
        /// <returns></returns>
        public bool Begin(ref Team _BattingTeam, ref Match _match)
        {
            if (_BattingTeam == null || _match == null)
            {
                BatsmanFacing = null;
                match = null;
                return false;
            }

            if (_BattingTeam.players == null)
            {
                BatsmanFacing = null;
                match = null;
                return false;
            }

            if (_BattingTeam.players.First(c => c.IsOnStrike == true) == null)
            {
                BatsmanFacing = null;
                match = null;
                return false;
            }

            match = _match;
            BatsmanFacing = _BattingTeam.players.First(c => c.IsBowlingCurrently == true);
            BatsmanSkillPoints = BatsmanFacing.BattingSkillPoints;
            
            return true;
        } //End of Begin

        public short GenerateShotRegion(double _MRF)
        {
            if (BatsmanFacing == null)
                return -1;

            List<short> BattingRegion = new List<short>(100);
                      
            return 0;
        } //End of GenerateShotRegion

        /// <summary>
        /// Generates the shot.
        /// </summary>
        /// <param name="_MRF">The MatchRiskFactor.</param>
        /// <returns>Enum shot</returns>
        public int GenerateShot(short _MRF)
        {
            if (BatsmanFacing == null)
                return -1;

            return 0;
        } //End of GenerateShot

        /// <summary>
        /// Generates the position where batsman comes down to hit
        /// </summary>
        /// <param name="_MRF">The MRF.</param>
        /// <returns>
        /// The generated Runup Length as a float
        /// </returns>
        public float GeneratePitchLocation(short _MRF)
        {
            if (BatsmanFacing == null)
                return -1.0f;
            
            return 0f;
        } //End of GeneratePitchLocation

        /// <summary>
        /// Generates the shot speed of Batsman.
        /// </summary>
        /// <param name="_MRF">The MatchRiskFactor.</param>
        /// <param name="AlternateBall">if set to <c>true</c> [bowl slower ball]. This is set from User window</param>
        /// <returns>The Speed as float as Km/Hr</returns>
        public float GenerateShotSpeed(short _MRF, float _PitchLocation)
        {
            if (BatsmanFacing == null)
                return -1.0f;
            
            return 0f;
        } //End of GenerateShotSpeed

        public float GenerateShotElevation(short _MRF)
        {
            if (BatsmanFacing == null)
                return -1.0f;
            
            return 0f;
        } //End of GenerateShotElevation

    } //End of class

} //End of Namespace
